package com.qf.lanzhou.blog.api.controller;

import com.qf.lanzhou.blog.api.pojo.entity.Role;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 是柠檬甜
 * @ClassName PermissionsCheckServlet
 * @description 权限验证功能
 * @date 2020/12/19 16:14
 * @modifier 是柠檬甜
 * @date 2020-12-19 16:14
 * @Version V1.0
 */
@WebServlet("/permissionsCheck.do")
public class PermissionsCheckServlet extends BaseServletPost{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Role> roles = (List) req.getSession().getAttribute("role");
        System.out.println(roles+"是柠檬甜");
        for (Role role:roles) {
            if (role.getId()==100L){
                successResultWrite(0,resp);
                return;
            }
            if (role.getId()==101L){
                System.out.println(role.getId()+"\"是柠檬甜\"");
                successResultWrite(1,resp);
                return;
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
